package morphing;

import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;

import javax.imageio.ImageIO;

public class Exec {

	
public static void main(String args[]) throws Exception {
		
		try {
		
		BufferedImage origin = ImageIO.read(new File("c:\\triangulo.jpg"));
		
		BufferedImage destiny = ImageIO.read(new File("c:\\davi.jpg"));
		
		int transicoes = 5;
		
		ArrayList<Line2D.Double> vetor1 = new ArrayList<Line2D.Double>();
		Line2D.Double linha1 = new Line2D.Double(14,48,18,37);
		vetor1.add(linha1);
		Line2D.Double linha2 = new Line2D.Double(18,37,15,26);
		vetor1.add(linha2);
		Line2D.Double linha3 = new Line2D.Double(15,26,26,26);
		vetor1.add(linha3);
		Line2D.Double linha4 = new Line2D.Double(26,26,32,18);
		vetor1.add(linha4);
		Line2D.Double linha5 = new Line2D.Double(32,18,37,26);
		vetor1.add(linha5);
		Line2D.Double linha6 = new Line2D.Double(37,26,49,26);
		vetor1.add(linha6);
		Line2D.Double linha7 = new Line2D.Double(49,26,44,37);
		vetor1.add(linha7);
		Line2D.Double linha8 = new Line2D.Double(44,37,50,48);
		vetor1.add(linha8);
		Line2D.Double linha9 = new Line2D.Double(50,48,37,48);
		vetor1.add(linha9);
		Line2D.Double linha10 = new Line2D.Double(37,48,31,57);
		vetor1.add(linha10);
		Line2D.Double linha11 = new Line2D.Double(31,57,26,48);
		vetor1.add(linha11);
		Line2D.Double linha12 = new Line2D.Double(26,48,14,48);
		vetor1.add(linha12);
		
		
		ArrayList<Line2D.Double> vetor2 = new ArrayList<Line2D.Double>();
		linha1 = new Line2D.Double(15,47,18,39);
		vetor2.add(linha1);
		linha2 = new Line2D.Double(18,39,22,33);
		vetor2.add(linha2);
		linha3 = new Line2D.Double(22,33,25,26);
		vetor2.add(linha3);
		linha4 = new Line2D.Double(25,26,31,17);
		vetor2.add(linha4);
		linha5 = new Line2D.Double(31,17,36,23);
		vetor2.add(linha5);
		linha6 = new Line2D.Double(36,23,41,31);
		vetor2.add(linha6);
		linha7 = new Line2D.Double(41,31,46,38);
		vetor2.add(linha7);
		linha8 = new Line2D.Double(46,38,50,46);
		vetor2.add(linha8);
		linha9 = new Line2D.Double(50,46,42,47);
		vetor2.add(linha9);
		linha10 = new Line2D.Double(42,47,34,47);
		vetor2.add(linha10);
		linha11 = new Line2D.Double(34,47,25,47);
		vetor2.add(linha11);
		linha12 = new Line2D.Double(25,47,15,47);
		vetor2.add(linha12);
		
		
		Morphing_ ota = new Morphing_(origin, destiny, vetor1, vetor2, transicoes, true);
		ArrayList imagens = ota.morph();
		
		for(int i=0; i<imagens.size(); i++)
		{
			BufferedImage resultadoBuffer = (BufferedImage)imagens.get(i);
		
			ImageIO.write(resultadoBuffer, "PNG", new File("c:/morphing"+i+".png"));
			
			
			
		}
		} catch( Exception e) {
			e.printStackTrace();
		}
	}

	

	/*
	public static void main(String args[]){
	
	try {

			BufferedImage origin = ImageIO.read(new File("chess.jpg"));

			ArrayList<Line2D.Double> vetor1 = new ArrayList<Line2D.Double>();
			vetor1.add(new Line2D.Double(155,292,155,46));
			vetor1.add(new Line2D.Double(155,46,334,46));
			vetor1.add(new Line2D.Double(334,46,334,292));
			vetor1.add(new Line2D.Double(334,292,155,292));
			
			ArrayList<Line2D.Double> vetor2 = new ArrayList<Line2D.Double>();
			vetor2.add(new Line2D.Double(202,245,202,89));
			vetor2.add(new Line2D.Double(202,89,292,89));
			vetor2.add(new Line2D.Double(292,89,292,245));
			vetor2.add(new Line2D.Double(292,245,202,245));
			
			
			Warping warp = new Warping(true);
			BufferedImage resultado = warp.warping(vetor1, vetor2, origin);
			
			ImageIO.write(resultado, "jpg", new File("warp.jpg"));
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	*/
}
